package com.cmrx.model.fiter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class MyFilter implements Filter {
	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
	
	}
	
	@Override
	public void doFilter(ServletRequest requ, ServletResponse resp, FilterChain filterChain)
			throws IOException, ServletException {
		System.out.println("filter:+=========" + System.currentTimeMillis());
		requ.setCharacterEncoding("UTF-8");
		HttpServletRequest request = (HttpServletRequest) requ;
		HttpServletResponse response = (HttpServletResponse) resp;
		response.addHeader("Access-Control-Allow-Origin", "*");
		response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
		response.addHeader("Access-Control-Allow-Headers",
				"Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers,token");
		filterChain.doFilter(request, response);
	}
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
	}
}


